﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Composite.Presentation.Commands;
using Microsoft.Practices.Composite.Presentation.Events;
using WPF60.Infrastructure.CabSupport;
using WPF60.Infrastructure.Events;
using WPF60.Infrastructure.Model;
using WPF60.Infrastructure.Services;
using WPF60.Infrastructure.Utility;

namespace WPF60.DemoModule.Views.LeftNav
{
    class LeftNavPresenter : PresenterBase<ILeftNavView, ILeftNavViewModel>
    {
        private readonly IDemoPageProvider _demoPageProvider;
        private readonly IEventAggregator _eventAggregator;

        public LeftNavPresenter(IDemoPageProvider demoPageProvider, IEventAggregator eventAggregator)
        {
            _demoPageProvider = demoPageProvider;
            _eventAggregator = eventAggregator;
        }

        public override void Setup()
        {
            ViewModel.SelectedPageCommand = 
                new DelegateCommand<object>(PageSelectedCommand, o => true);

            _demoPageProvider.LoadDemoPages().ForEach(
                page => ViewModel.Pages.Add(page));

            base.Setup();
        }

        private void PageSelectedCommand(object obj)
        {
            _eventAggregator.GetEvent<PageSelectedEvent>().Publish((DemoPage) obj);
        }
    }


}
